class Solution
{
public:
    vector<string> letterCasePermutation(string s)
    {
        vector<string> result;
        letterCasePermutation(s, 0, result);
        return result;
    }

    void letterCasePermutation(string &s, int index, vector<string> &result)
    {
        if (index == s.size())
        {
            result.push_back(s);
            return;
        }
        letterCasePermutation(s, index + 1, result);
        char sc = s[index];
        if ((sc >= 'a' && sc <= 'z') || (sc >= 'A' && sc <= 'Z'))
        {
            s[index] ^= 32;
            letterCasePermutation(s, index + 1, result);
            s[index] ^= 32;
        }
    }
};